package olap4cloud.hbase.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang.time.DateUtils;

public class MyDateUtil {

	
	public static String MY_DATEFORMAT = "yyyy-MM-dd'-'HH'h'-mm'p'";
	public static SimpleDateFormat simpleformat = new SimpleDateFormat(MY_DATEFORMAT);;
	
	public MyDateUtil(){
		
	}
	
	public static String getFolder(){
		return simpleformat.format(new Date());
	}
	
	public static long roundDownMinutes(long time, int minutesFix){
		return (time/(minutesFix*60*1000)*(minutesFix*60*1000));
	}
		
	public static long roundDownDateTime (long time){
		return DateUtils.truncate(new Date(time), Calendar.DATE).getTime();	
	}
	
	public static long roundDownHourTime (long time){
		return DateUtils.truncate(new Date(time), Calendar.HOUR_OF_DAY).getTime();
	}
	
	public static long roundUpHourTime (long time){
		
		//return DateUtils.round(new Date(time), Calendar.HOUR_OF_DAY).getTime();
		return roundDownHourTime(time + 60 * 60 * 1000);
	}
	
	public static long roundUpDateTime(long time){
		//return DateUtils.round(new Date(time), Calendar.DATE).getTime();
		return roundDownDateTime(time + 24 * 60 * 60 * 1000);
	}
	
	public static void main(String[] args) {
		//long time =  2082646800000;
		long time = 1355811603606l;
		Date date = new Date(time);
		System.out.println(date);
		System.out.println("round date "+new Date(roundDownDateTime(date.getTime())));
		System.out.println(new Date(roundDownHourTime(date.getTime())));
		System.out.println(new Date(roundDownMinutes(date.getTime(), 5)));
	}
}
